// pages/work/list.js
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tasks: [],
        page: 1,
        tip: '上拉加载',
        loading: false,
        type: 1,


        current: 'tab1',
        loading2: false,
        loading3: false,
     
        tip2: '',
        tip3: '上拉加载',
        p1: 1,
        p2: 1,
        p3: 1,
        is_pull1: true,
        is_pull2: true,
        is_pull3: true,
        myupload: [],

        //第一次进入tab2的标记
        enter1: true,
        enter2: false,
        enter3: false,
        tip: '上拉加载',
        data1: [],
        data2: [],
        data3: [],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        wx.getSystemInfo({
            success: (res) => {
                this.setData({
                    height: (((res.windowHeight - 42) * 750) / res.windowWidth)
                })
            }
        })
       this.getTask();
    },
  

    getTask() {
        let that = this;
        this.setData({
            tip: '正在加载',
            loading: true,
            type: this.data.type
        })
        app.http.$ajax(
            {
                url: 'v1.task/getTask',
                data: { 
                    page:this.data.page,
                    type: this.data.type
                },
                loading: false
            },
            {
                success(data) {
                    let pagedata = app.util.pageshow(data.data)
                    that.data.tasks.push(...data.data.data);
                    that.data.page++;
                    console.log(pagedata)
                    that.setData({
                        tasks: that.data.tasks,
                        ...pagedata
                    });
                }
            }
        )
    },

    handleChange({ detail }) {
       //置空所有的
       this.setData({
           tasks: [],
           page: 1,
           tip: '上拉加载',
           current: detail.key
       });

       if(detail.key == 'tab1') {
           this.data.type = 1
       } else if(detail.key == 'tab2') {
        this.data.type = 2
       } else {
        this.data.type = 3
       }

       this.getTask();
    },
    
    lower() {
        //滚动到底部
        if(this.data.tip != '没有更多数据') {
            this.getTask()
        }
    },

    goto(e) {
        let id = e.currentTarget.dataset.id;
        wx.navigateTo({
          url: '/pages/v4_sass/my/detail?id=' + id,
        })
    },
    
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        
        
    },

})